class Solution
{
public:
    int countElements(vector<int> &nums)
    {
        sort(nums.begin(), nums.end());
        int front = 0;
        int back = nums.size() - 1;
        if (nums[front] == nums[back])
        {
            return 0;
        }
        ++front;
        --back;
        while (nums[front] == nums[front - 1])
        {
            ++front;
        }
        while (nums[back] == nums[back + 1])
        {
            --back;
        }
        return back - front + 1;
    }
};